package com.bt.springboot.rabbitmq;

import com.bt.springboot.config.DelayedExchangeConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author zkx
 * @Date 2024/1/6 16:04
 */
@Component
public class DelayedMessageProducer {

	@Autowired
	private RabbitTemplate rabbitTemplate;

//	@Scheduled(fixedDelay = 1000)
	public void sendDelayedMessage(String message){
		rabbitTemplate.convertAndSend(DelayedExchangeConfig.DELAYED_EXCHANGE_NAME
				,DelayedExchangeConfig.DELAYED_ROUTING_KEY,
				message,
				messagePostProcessor ->{
					// 设置延迟时间 单位毫秒
					messagePostProcessor.getMessageProperties().setDelay(10000);
					return messagePostProcessor;
				});
	}
}
